package com.yc.sole.system.biz;

import cn.hutool.core.bean.BeanUtil;
import com.yc.sole.framework.mybatis.page.Paging;
import com.yc.sole.framework.mybatis.util.PageUtil;
import com.yc.sole.system.dto.LogDto;
import com.yc.sole.system.repository.LogRepository;
import com.yc.sole.system.request.LogQueryReq;
import com.yc.sole.system.response.LogResp;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * 服务接口实现
 *
 * @author yizuomin
 * @date 2023-04-01
 **/
@Slf4j
@Service
@RequiredArgsConstructor
public class LogBiz {

    private final LogRepository logRepository;

    /**
     * 删除
     *
     * @param ids
     */
    @Transactional(rollbackFor = Exception.class)
    public void deleteLog(List<Long> ids) {
        logRepository.deleteLog(ids);
    }

    /**
     * 分页查询
     *
     * @param page
     * @param logQueryReq
     * @return
     */
    public Paging<LogResp> selectLogPage(Paging<LogQueryReq> page, LogQueryReq logQueryReq) {
        Paging<LogDto> paging = logRepository.selectLogPage(page, logQueryReq);
        return PageUtil.pageCopy(paging, LogResp.class);
    }

    /**
     * 通过id查询日志详情
     *
     * @param logId
     * @return
     */
    public LogResp selectLogById(Long logId) {
        return BeanUtil.copyProperties(logRepository.selectLogById(logId), LogResp.class);
    }
}
